package com.house.service.impl;

import com.github.pagehelper.PageHelper;
import com.house.entity.House;
import com.house.mapper.HouseMapper;
import com.house.service.HouseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author asus
 * @since 2021-02-28
 */
@Service
public class HouseServiceImpl implements HouseService {

    @Resource
    private HouseMapper houseMapper;

    /**
     * 按照房间价格区间查询房屋
     *
     * @param startPrice
     * @param endPrice
     * @return
     */
    @Override
    public List<House> selectHousesByHousePrice(BigDecimal startPrice, BigDecimal endPrice) {
        return houseMapper.selectHousesByHousePrice(startPrice, endPrice);
    }

    /**
     * 按照房间合租男性或女性的数量查询房间
     * 按照房间的室数和厅数的数量查询房间
     *
     * @param roomNum
     * @param hallNum
     * @param maleNum
     * @param femaleNum
     * @return
     */
    @Override
    public List<House> selectHousesByHouseType(Integer roomNum, Integer hallNum, Integer maleNum, Integer femaleNum) {
        return houseMapper.selectHousesByHouseType(roomNum, hallNum, maleNum, femaleNum);
    }

    @Override
    public Integer insertOneHouse(House house) {
        return houseMapper.insertOneHouse(house);
    }

    @Override
    public int deleteOneHouse(Integer houseId) {
        return houseMapper.deleteOneHouse(houseId);
    }

    /**
     * 按照房间的地段查询房间
     *
     * @param housePlace
     * @return
     */
    @Override
    public List<House> selectHousesByHousePlace(String housePlace) {
        return houseMapper.selectHousesByHousePlace(housePlace);
    }

    /**
     * 按照房间的面积查询房间
     *
     * @param minArea
     * @param maxArea
     * @return
     */
    @Override
    public List<House> selectHousesByHouseArea(Integer minArea, Integer maxArea) {
        return houseMapper.selectHousesByHouseArea(minArea, maxArea);
    }


    @Override
    public List<House> selectAllHouse() {
        return houseMapper.selectAllHouse();
    }

    @Override
    public House selectHouseByHouseId(Integer houseId) {
        House house = houseMapper.selectHouseByHouseId(houseId);
        return house;
    }

    @Override
    public Integer updateHousePictures(Integer houseId, String housePhotos) {
        int index = houseMapper.updateHousePictures(houseId, housePhotos);
        return index;
    }

    @Override
    public List<Integer> selectHasReleaseHouseId(Integer releaseId) {
        return houseMapper.selectHasReleaseHouseId(releaseId);
    }

    @Override
    public List<House> selectHouseByReleaseId(Integer releaseId) {
        return houseMapper.selectHouseByReleaseId(releaseId);
    }

    @Override
    public List<House> selectHouseByHouseTypeAndHousePriceAndCentType(Integer roomNum, Integer rentType, Integer housePrice) {
        BigDecimal startPrice = null;
        BigDecimal endPrice = null;
        if (housePrice == 1) {
            startPrice = new BigDecimal("0");
            endPrice = new BigDecimal("500");
        }
        if (housePrice == 2) {
            startPrice = new BigDecimal("500");
            endPrice = new BigDecimal("1000");
        }
        if (housePrice == 3) {
            startPrice = new BigDecimal("1000");
            endPrice = new BigDecimal("1500");
        }
        if (housePrice == 4) {
            startPrice = new BigDecimal("1500");
            endPrice = new BigDecimal("2000");
        }
        if (housePrice == 5) {
            startPrice = new BigDecimal("2000");
            endPrice = new BigDecimal("3000");
        }
        if (housePrice == 6) {
            startPrice = new BigDecimal("3000");
            endPrice = new BigDecimal("5000");
        }
        if (housePrice == 7) {
            endPrice = new BigDecimal("5000");
        }
        List<House> houseList = houseMapper.selectHouseByHouseTypeAndHousePriceAndCentType(roomNum, rentType, startPrice, endPrice);
        return houseList;
    }

    @Override
    public Integer updateOneHouse(House house) {
        return houseMapper.updateOneHouse(house);
    }


}
